package com.ccp.dev.system.service;

import com.ccp.dev.core.basic.base.BaseService;
import com.ccp.dev.system.dao.SysTypeKeyDao;
import com.ccp.dev.system.model.SysTypeKey;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

/**
 * SysTypeKey service类
 *
 * @author zhaowj
 */
@Service
public class SysTypeKeyService extends BaseService<SysTypeKey> {

    @Resource
    private SysTypeKeyDao sysTypeKeyDao;

    /**
     * 根据key取得SysTypeKey对象
     * @param typeKey 分类key
     * @return SysTypeKey对象
     */
    public SysTypeKey getByKey(String typeKey){
        return sysTypeKeyDao.getByKey(typeKey);
    }

    /**
     * 排序保存
     * @param typeIds
     */
    public int updateSequence(String[] typeIds){
        int result = 0;
        for(int i=0;i<typeIds.length;i++){
            SysTypeKey sysTypeKey = new SysTypeKey();
            sysTypeKey.setTypeId(typeIds[i]);
            sysTypeKey.setSn(i);
            result = result + this.sysTypeKeyDao.updateSequence(sysTypeKey);
        }
        return result;
    }

    /**
     * 根据typeKey判断是否存在
     * @param sysTypeKey
     * @return
     */
    public List<SysTypeKey> getByTypeKey(SysTypeKey sysTypeKey){
        return this.sysTypeKeyDao.getByTypeKey(sysTypeKey);
    }

    /**
     * 获取所有分类
     * @return
     */
    public List<SysTypeKey> queryAllTypeKey(){
        return this.sysTypeKeyDao.queryAllTypeKey();
    }

}
